package cn.edu.zjut.mina.protocal;

import java.nio.charset.Charset;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

import cn.edu.zjut.mina.util.HDecoder;
import cn.edu.zjut.mina.util.HEncoder;
/** 
 * JMessageProtocal解码编码工厂 
 *  
 * @author Simple 
 *  
 */
public class JMessageProtocalCodecFactory implements ProtocolCodecFactory {

//	private final JMessageProtocalDecoder decoder;
//	private final JMessageProtocalEncoder encoder;
	
	private final HDecoder decoder;
	private final HEncoder encoder;

	public JMessageProtocalCodecFactory() {
		this(Charset.forName("UTF-8"));

	}

	public JMessageProtocalCodecFactory(Charset charSet) {
//		this.encoder = new JMessageProtocalEncoder(charSet);
//		this.decoder = new JMessageProtocalDecoder(charSet);
		this.encoder = new HEncoder(charSet);
		this.decoder = new HDecoder(charSet);
	}

	public ProtocolDecoder getDecoder(IoSession arg0) throws Exception {
		return decoder;
	}

	public ProtocolEncoder getEncoder(IoSession arg0) throws Exception {
		return encoder;
	}
}